package main

import (
	message "chat/common"
	process2 "chat/server/process"
	"chat/server/utils"
	"fmt"
	"net"
)

type Processor struct {
	Conn net.Conn
}

func (that *Processor) serverProcessMes(mes *message.Message) (err error) {
	switch mes.Type {
	case message.LoginMesType:
		up := &process2.UserProcess{
			Conn: that.Conn,
		}
		err = up.ServerProcessLogin(mes, pool)
	case message.RegisterMesType:
		up := &process2.UserProcess{
			Conn: that.Conn,
		}
		err = up.ServerProcessRegister(mes, pool)
	case message.SmsMesType:
		up := &process2.SmsProcess{
			Conn: that.Conn,
		}
		up.ServerProcessSms(mes)
	default:
		fmt.Println("枚举错误")
	}
	return
}

func (that *Processor) process2() (err error) {
	for {
		tf := &utils.Transfer{
			Conn: that.Conn,
		}
		mes, err := tf.ReadPkg()
		if err != nil {
			fmt.Println("readPkg err=", err)
			return err
		}
		err = that.serverProcessMes(&mes)
		if err != nil {
			return err
		}
	}
}
